package com.lovo.middleman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.middleman.bean.CustomerBean;
import com.lovo.middleman.bean.SellBean;
import com.lovo.middleman.mapper.CustomerMapper;
import com.lovo.middleman.mapper.SellMapper;
import com.lovo.middleman.service.ISellService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SellServiceImpl extends ServiceImpl<SellMapper, SellBean> implements ISellService {

    @Autowired
    CustomerMapper customerMapper;

    @Autowired
    SellMapper sellMapper;

//    @Override
//    public List<SellBean> querySellBean(int userId) {
//        QueryWrapper<CustomerBean> queryWrapper = new QueryWrapper<>();
//        queryWrapper.gt("user_id", userId);
//        return customerMapper.;
//    }


    @Override
    public Page<SellBean> queryPageByItem(int curPage,
                                          int pageSize,
                                          String customerName,
                                          String startTime,
                                          String endTime) {
        QueryWrapper<SellBean> queryWrapper = new QueryWrapper<>();
        if (customerName != null && !"".equals(customerName)) {
            queryWrapper.like("customer_name", customerName);
        }
        if (startTime != null && !"".equals(startTime)) {
            queryWrapper.ge("sell_time", startTime);
        }
        if (endTime != null && !"".equals(endTime)) {
            queryWrapper.le("sell_time", endTime);
        }
        return sellMapper.selectPage(new Page<>(curPage, pageSize), queryWrapper);

    }

    @Override
    public void addSell(SellBean sellBean) {
        sellMapper.insert(sellBean);
    }

    @Override
    public SellBean querySellBeanById(int id) {
        return  sellMapper.selectById(id);

    }
}
